<?php

ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', E_ALL ^ E_DEPRECATED);

class CROUtil {
	function isDebug() {
		return false;
	}
	
	function nullToNone($val) {
		if ( $val ) {
			return $val;
		} else {
			return '';
		}
	}
	
	function theme() {
		return 'd';
	}

	function getParameter($name) {
		if ( isset($_REQUEST[$name]) ) {
			return CROUtil::nullToNone($_REQUEST[$name]);
		} else {
			return '';
		}
	}
	
	function getOrderType($typeId) {
		switch($typeId) {
			case 1:
				return 'Delivery';
			case 2:
				return 'Pick up';
			case 3:
				return 'Eat in';
		}		
	}
	
	function getDemoMenuId() {
		return -9999;
	}
	
	function isMobileBrowser() {
		$agent = $_SERVER['HTTP_USER_AGENT'];
		
		if(preg_match("/iPhone|Android|Blackberry/i", $agent)){
		    return true;
		} else {
			return false;
		}
	}
	function isAndroidBrowser() {
		$agent = $_SERVER['HTTP_USER_AGENT'];
		
		if(preg_match("/Android/i", $agent)){
		    return true;
		} else {
			return false;
		}
	}
	function join($a, $b, $sign) {
		if( strlen($a) < 1 ){
		    return $b;
		} else if( strlen($b) < 1 ){
		    return $a;
		} else {
			return $a.' '.$sign.' '.$b;
		}
	}
	
	function isShowMobileVersion() {
		if ( param('version') == 'm' ) {
			return true;
		}
		$agent = strtolower($_SERVER['HTTP_USER_AGENT']);		
		if(preg_match("/iphone/ipod|android|blackberry/mini/palm/windows ce/", $agent)){
		    return true;
		} else {
			return false;
		}		
	}	
}

function formatDecimal($val) {
	if ( $val ) {
		return sprintf ("%4.2f", $val);
	} else {
		echo '0.00';
	}
}

function sqlEscape($val) {
	return addslashes($val);
}

function requireFile($fileName, &$db, $restaurant, $isDemo=null, $isMobile=null, $deviceId=null, $numOfCat=null, $categoryList=null) {
	if ( $isMobile ) {
		require_once $fileName.'_m.php';
	} else {
		require_once $fileName.'_d.php';
	}
}

function param($name) {
	if ( isset($_REQUEST[$name]) ) {
		return $_REQUEST[$name];
	}
	return null;
}



function isPostback()  {
	if ( strlen(param('isPostback')) > 0 ) {
		return true;
	} else {
		return false;
	}
}

function paramEscape($name) {
	$val = param($name);
	if ( !$val ) {
		return $val;
	}
	return addslashes($val);
}

function error($errorMessage) {
	global $ErrorMessage;
	$ErrorMessage = $errorMessage;
}
function logParameter($str) {
	if ( !$str ) {
		return;
	}
	global $logParameterStr;
	if ( $logParameterStr ) {
		$logParameterStr .= '||';
	}
	$logParameterStr .= $str;
}

function getDemoClass($isDemo) {
	if ( $isDemo ) {
		return 'demo';
	} else {
		return '';
	}
}

function checkGet($row, $name) {
	if ( isset($row[$name]) ) {
		return $row[$name];
	} else {
		return '';
	}
}

?>